package com.lcq.gulimall.order.controller;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.lcq.gulimall.order.entity.OrderEntity;
import com.lcq.gulimall.order.entity.PaymentInfoEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @RequestMapping("/sendOrder")
    public String sendOrder(){
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setId(1L);
        orderEntity.setMemberUsername("张三");
        rabbitTemplate.convertAndSend("hello-exchange","dog.guard",orderEntity);
        return "OK";
    }

    @RequestMapping("/createOrder")
    public String createOrder(){
        OrderEntity orderEntity = new OrderEntity();
        String timeId = IdWorker.getTimeId();
        orderEntity.setOrderSn(timeId);
        rabbitTemplate.convertAndSend("order-event-exchange","order.delay.queue",orderEntity);
        return "OK";
    }

    @RequestMapping("/sendPayment")
    public String sendPayment(){
        PaymentInfoEntity paymentInfoEntity = new PaymentInfoEntity();
        paymentInfoEntity.setId(2L);
        paymentInfoEntity.setAlipayTradeNo("456789");
        rabbitTemplate.convertAndSend("hello-exchange","dog.guard",paymentInfoEntity);
        return "OK";
    }

    @RequestMapping("/sendError")
    public String sendError(){
        PaymentInfoEntity paymentInfoEntity = new PaymentInfoEntity();
        paymentInfoEntity.setId(2L);
        paymentInfoEntity.setAlipayTradeNo("456789");
        rabbitTemplate.convertAndSend("hello-exchange","dog.6666",paymentInfoEntity);
        return "OK";
    }

}
